﻿#pragma once

#include "MirImageControl.h"
#include "MirLabel.h"
#include "../../Shared/Data/ItemData.h"
#include "../../Shared/Enums.h"
#include <string>
#include <vector>
#include "exceptionhelper.h"
#include "../../tangible_event.h"
#include "../../stringhelper.h"

using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirObjects;
using namespace Client::MirScenes;
using namespace Client::MirSounds;
using namespace Client::MirScenes::Dialogs;
namespace C = ClientPackets;

namespace Client::MirControls
{
    class MirItemCell final : public MirImageControl
    {
    private:
        MirLabel *CountLabel;

    public:
        UserItem *getItem() const;
        void setItem(UserItem *value);

        UserItem *getShadowItem() const;

        std::vector<UserItem*> getItemArray() const;

        bool getBorder() const override;

    private:
        bool _locked = false;

    public:
        bool getLocked() const;
        void setLocked(bool value);



        #pragma region GridType

    private:
        MirGridType _gridType = static_cast<MirGridType>(0);
    public:
        TangibleEvent<EventHandler> *GridTypeChanged = new TangibleEvent<EventHandler>();
        MirGridType getGridType() const;
        void setGridType(MirGridType value);

    private:
        void OnGridTypeChanged();
        #pragma endregion

        #pragma region ItemSlot

        int _itemSlot = 0;
    public:
        TangibleEvent<EventHandler> *ItemSlotChanged = new TangibleEvent<EventHandler>();
        int getItemSlot() const;
        void setItemSlot(int value);

    private:
        void OnItemSlotChanged();
        #pragma endregion

        #pragma region Count Label

        MirLabel *getCountLabel() const;
        void setCountLabel(MirLabel *value);

        #pragma endregion

    public:
        MirItemCell();

        void SetEffect();


        void OnMouseClick(MouseEventArgs *e) override;
        void OnMouseDoubleClick(MouseEventArgs *e) override;


    private:
        void BuyItem();

    public:
        void OpenItem();

        void UseItem();
        void UseSlotItem();

        void RemoveItem();

    private:
        void MoveItem();
        void PlayItemSound();

        int FreeSpace();


        bool CanRemoveItem(UserItem *i);

        bool CorrectSlot(UserItem *i);
        bool CanUseItem();

        bool CanWearItem(UserItem *i);

    protected:
        void DrawControl() override;

        void OnMouseEnter() override;
        void OnMouseLeave() override;

    private:
        void CreateDisposeLabel();
        void DisposeCountLabel();
    };
}
